﻿/*
 * RegExpress
 * 
 * Copyright (c) 2010, Daniel McGaughran
 * 
 * Licensed under the Apache Licence, Version 2.0 (the "Licence");
 * you may not use this file except in compliance with the Licence.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the Licence is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Licence for the specific language governing permissions and
 * limitations under the Licence.
 * 
 */

using System;


namespace RegExpressModel
{
	public class RestorableSettings<T> where T : ISettingsInfo, new()
	{
		private T _originalSettings;
		private T _changedSettings;



		public RestorableSettings()
		{
			_originalSettings = new T();
			_changedSettings = new T();
			RevertChanges();
		}



		public T CurrentSettings
		{
			get { return _changedSettings; }
		}


		public T SavedSettings
		{
			get { return _originalSettings; }
		}



		public bool AreChangesPending()
		{
			return !_originalSettings.IsEqualTo(_changedSettings);
		}



		public bool ApplyChanges()
		{
			return _originalSettings.SetValues(_changedSettings);
		}



		public bool RevertChanges()
		{
			return _changedSettings.SetValues(_originalSettings);
		}


	}
}
